#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define MAXN 310
 
int match1[MAXN], match2[MAXN];
int mat[MAXN][MAXN];
int m, n, temp, t, T, ans;
 
int hungary(){
    int s[MAXN],t[MAXN],p,q,ret=0,i,j,k;
    memset(match1, -1, sizeof(match1));
    memset(match2, -1, sizeof(match2));
    for(i=0;i<m;ret+=match1[i++]>=0){
        memset(t, -1, sizeof(t));
        for(s[p=q=0] = i;p <= q&&match1[i] < 0;p++){
            for(k=s[p],j=0;j<n&&match1[i] < 0;j++){
                if(mat[k][j]&&t[j] < 0){
                    s[++q] = match2[j], t[j] = k;
                    if(s[q] < 0){
                        for(p = j;p >= 0;j = p){
                            match2[j] = k = t[j];
                            p = match1[k];
                            match1[k] = j;
                        }
                    }
                }
            }
        }
    }
    return ret;
}
int main(){
   
    while(scanf("%d", &T)!=EOF){
        while(T--){
            memset(mat, 0, sizeof(mat));
            scanf("%d%d", &m, &n);
            for(int i=1;i<=m;i++){
                scanf("%d",&temp);
                for(int j=1;j<=temp;j++){
                    scanf("%d", &t);
                    mat[i-1][t-1] = 1;
                }
            }
            ans = hungary();
            if(ans==m){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }
    }
    return 0;
}
